import Vue from 'vue'
import Router from 'vue-router'
import NProgress from 'nprogress' // progress bar
import 'nprogress/nprogress.css'// progress bar style

const MainMenu = () => import(/* webpackChunkName: "group-main" */ '@/layouts/MainMenu')
const MenuHomeIndex = () => import(/* webpackChunkName: "group-main" */ '@/pages/home/Index')
const MenuBookmarkIndex = () => import(/* webpackChunkName: "group-main" */ '@/pages/bookmark/Index')

const MainBlank = () => import(/* webpackChunkName: "group-blank" */ '@/layouts/MainBlank')
const BlankOrderIndex = () => import(/* webpackChunkName: "group-main" */ '@/pages/order/Index')
const BlankSuccessIndex = () => import(/* webpackChunkName: "group-main" */ '@/pages/success/Index')

const NotFound = () => import(/* webpackChunkName: "group-404" */ '@/layouts/404')

Vue.use(Router)

const router = new Router({
  mode: 'history',
  base: __dirname,
  routes: [
    {
      path: '/menu',
      name: 'MainMenu',
      component: MainMenu,
      alias: '',
      children: [
        {
          path: 'home',
          name: 'MenuHomeIndex',
          component: MenuHomeIndex,
          alias: ''
        }, {
          path: 'bookmark',
          name: 'MenuBookmarkIndex',
          component: MenuBookmarkIndex
        }
      ]
    },
    {
      path: '/blank',
      name: 'MainBlank',
      component: MainBlank,
      children: [
        {
          path: 'order',
          name: 'BlankOrderIndex',
          component: BlankOrderIndex,
          alias: ''
        }, {
          path: 'success',
          name: 'BlankSuccessIndex',
          component: BlankSuccessIndex
        }
      ]
    },
    {path: '*', component: NotFound}
  ]
})

// 全局前置导航守卫
router.beforeEach((to, from, next) => {
  // console.log(to, from)
  NProgress.start() // finish progress bar
  next()
})

router.afterEach(() => {
  NProgress.done() // finish progress bar
})
export default router
